package us.icitap.cm.business.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="ORG_STRUCTURE",schema="MPC")
public class OrgStructure implements Serializable {

	@Id
	private Integer id;
	@Column
	private String name;
	
	@ManyToOne
	@JoinColumn(name="PARENT_ORG_STRUCT_ID")
	private OrgStructure parentOrgStructure;
	
	private boolean active = true;
	
	public OrgStructure(){}
	
	public OrgStructure(Integer id, String name){
		this.id = id;
		this.name = name;
	}
 
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}



	public OrgStructure getParentOrgStructure() {
		return parentOrgStructure;
	}

	public void setParentOrgStructure(OrgStructure parentOrgStructure) {
		this.parentOrgStructure = parentOrgStructure;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (active ? 1231 : 1237);
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime
				* result
				+ ((parentOrgStructure == null) ? 0 : parentOrgStructure
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OrgStructure other = (OrgStructure) obj;
		if (active != other.active)
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (parentOrgStructure == null) {
			if (other.parentOrgStructure != null)
				return false;
		} else if (!parentOrgStructure.equals(other.parentOrgStructure))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.id + ", " + this.name;
	}

	
}
